using System.IO;
using SocialShare.DataAccessLayer;
using System;

namespace SocialShare.Helpers
{
    /// <summary>
    /// Execute sql statements explicitly
    /// </summary>
    public sealed class SqlScriptRunner
    {
        /// <summary>
        /// Execute all sql statmens contained in a give file
        /// </summary>
        /// <param name="scriptPath">Physical path of the sql file </param>
        public static void RunScript(String scriptPath)
        {
            using (SocialShareDatabaseContext _DatabaseContext = new SocialShareDatabaseContext())
            {                
                _DatabaseContext.ExecuteStoreCommand(File.ReadAllText(scriptPath));
            }

        }

        /// <summary>
        /// Execute valid sql statement
        /// </summary>
        /// <param name="sqlStatement">sql statement to execute</param>
        public static void RunSqlScript(String sqlStatement)
        {
            using (SocialShareDatabaseContext _DatabaseContext = new SocialShareDatabaseContext())
            {
                _DatabaseContext.ExecuteStoreCommand(sqlStatement);
            }
        }
       
    }
}
